package com.tobias.gaokao.exception;

import com.tobias.gaokao.constants.Result;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class AppExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(AppExceptionHandler.class);

    @ResponseBody
    @ExceptionHandler(Throwable.class)
    public Object handleException(HttpServletRequest request, Throwable e) {
        logger.error("msg:{},url:{}", ((AppException)e).getMsg(), request.getRequestURL());
        return new Result<String>(((AppException) e).getCode()+"",((AppException) e).getMsg(),((AppException) e).getData());
    }
}

